/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : waiting_list.js                                 
*  Description  : 웨이팅 예약 리스트
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-07-27  김효순    Created.  
*******************************************************************************/

jQuery(function($){
	$("div.my_set").remove();
	$("div#container section#main_content div.area_search select:eq(2)").remove();
	
	// 지역선택
	function clsAreaList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsAreaList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.area_search select:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.setList([]);
			this.setIdx(0);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setList: function(thisData){
			this.listData = [{
				"지역코드": ""
				, "지역명": "지역 선택"
			}].concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append("<option />");
			}
			$layer.find("option").each(function(n){
				$(this).text(thisClass.listData[n]["지역명"]);
			});
		}
		, setIdx: function(idx){
			this.$getLayer().find("option").eq(idx).attr("selected", "selected");
		}
		, setKey: function(key){
			for(var i=0;i<this.listData.length;i++){
				if(key == this.listData[i]["지역코드"]) break;
			}
			
			if(i<this.listData.length) this.setIdx(i);
			this.$getLayer().trigger("change");
		}
		, getValue: function(){
			var $layer = this.$getLayer();
			var n = $layer.find("option").index($layer.find("option:selected"));
			
			return this.listData[n]["지역코드"];
		}
	}
	
	// 골프장 코스 선택
	function clsGolfCourseList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsGolfCourseList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content div.area_search select:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.reset();
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, reset: function(){
			this.setList([]);
			this.setIdx(0);
		}
		, setList: function(thisData){
			this.listData = [{
				"골프장코드": ""
				, "골프장명": "골프장"
				, "코스코드": ""
				, "코스명": "코스 선택"
			}].concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append("<option />");
			}
			$layer.find("option").each(function(n){
				$(this).text(thisClass.listData[n]["골프장명"] + "-" + thisClass.listData[n]["코스명"]);
			});
		}
		, setIdx: function(idx){
			this.$getLayer().find("option").eq(idx).attr("selected", "selected");
		}
		, getGolfKey: function(){
			var $layer = this.$getLayer();
			var n = $layer.find("option").index($layer.find("option:selected"));
			
			return this.listData[n]["골프장코드"];
		}
		, setCourseKey: function(key){
			for(var i=0;i<this.listData.length;i++){
				if(key == this.listData[i]["코스코드"]) break;
			}
			
			if(i<this.listData.length) this.setIdx(i);
		}
		, getCourseKey: function(){
			var $layer = this.$getLayer();
			var n = $layer.find("option").index($layer.find("option:selected"));
			
			return this.listData[n]["코스코드"];
		}
	}
	
	// 2주력
	function clsWeekCalendar()
	{
		this._HTMLDom = null;
		this.sDate = null;
		this.selDate = null;
		
		this._init();
	}
	
	clsWeekCalendar.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_area:first thead");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("th:gt(0)").css("cursor", "pointer");
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setDate: function(newDate){
			this.sDate = newDate;
			this.display();
		}
		, setSelDate: function(newDate){
			this.selDate = newDate;
			this.display();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			var aWeekday = ["일", "월", "화", "수", "목", "금", "토"];
			
			var m = this.sDate.getMonth()+1;
			$layer.find("th:eq(0)").html(m + "월");
			
			$layer.find("th:gt(1)").filter("th:not(.th_next)").css("cursor", "pointer").each(function(n){
				var newDate = new Date();
				newDate.setTime(thisClass.sDate.getTime());
				newDate.setDate(newDate.getDate() + n);
				
				$(this).data("date", newDate);
				$(this).find("p:eq(0)").html(aWeekday[newDate.getDay()]);
				$(this).find("p:eq(1)").html(newDate.getDate());
				
				$(this).attr("class", "");
				
				switch(newDate.getDay()){
					case 0:
						$(this).addClass("holiday");
						break;
					case 6:
						$(this).addClass("satday");
						break;
				}
				
				if(thisClass.selDate && newDate.getTime() == thisClass.selDate.getTime()) $(this).addClass("day_over");
			});
		}
		, getDate: function(){
			return this.sDate;
		}
		, getSelDate: function(){
			return this.selDate;
		}
		, getSatIndexs: function(){
			var $layer = this.$getLayer();
			var $sat = $layer.find("th").filter(function(){
				return $(this).hasClass("satday");
			});
			
			return [$layer.find("th:gt(1)").index($sat.eq(0)), $layer.find("th:gt(1)").index($sat.eq(1))];
		}
		, getSunIndexs: function(){
			var $layer = this.$getLayer();
			var $sun = $layer.find("th").filter(function(){
				return $(this).hasClass("holiday");
			});
			
			return [$layer.find("th:gt(1)").index($sun.eq(0)), $layer.find("th:gt(1)").index($sun.eq(1))];
		}
	}
	
	
	// 예약리스트
	function clsReserveList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this.orderIdx = null;
		this.idx = null;
		
		this._init();
	}
	
	clsReserveList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.reserve_list tbody");
			var $img = $layer.find("img[alt='웨이팅신청']:first, img[alt='신청취소']:first, img[alt='예약확정']:first");
			$layer.find("tr:first td.bt_re").empty().append($img);
			
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			
			this.orderIdx = 1;
			this.setList([]);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.idx = null;
			this.display();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($element.clone(true));
			}
			
			
			$layer.find("tr").each(function(n){
				$(this).attr("class", "");
				
				$(this).find("td:eq(0)").html(thisClass.listData[n]["지역명"]);
				$(this).find("td:eq(1)").html("<em>" + thisClass.listData[n]["골프장명"] + "</em> " + thisClass.listData[n]["코스명"]);
				$(this).find("td:eq(2)").html(thisClass.listData[n]["예약시간"]);
				$(this).find("td:eq(3)").html(thisClass.listData[n]["홀명"]);
				$(this).find("td:eq(4) p:eq(0)").html(_util.number_format(thisClass.listData[n]["가격"]));
				$(this).find("td:eq(4) p:eq(1)").html(_util.number_format(thisClass.listData[n]["원가"])).show();
				
				if(thisClass.listData[n]["가격"] == thisClass.listData[n]["원가"]) $(this).find("td:eq(4) p:eq(1)").hide();
				
				$(this).find("td:eq(5)").html(thisClass.listData[n]["신청대기"] + " <span>명</span>");
				$(this).find("td:eq(6)").html(thisClass.listData[n]["내상태"]);
				var bName = "";
				switch(thisClass.listData[n]["내상태코드"]){
					case "W001":
						$(this).find("td:eq(6)").textWrap(thisClass.listData[n]["내상태"], "<span />");
						bName = "신청취소";
						break;
					case "W002":
						$(this).find("td:eq(6)").textWrap(thisClass.listData[n]["내상태"], "<em />");
						bName = "신청취소,예약확정";
						break;
					default :
						bName = "웨이팅신청";
						break;
				}
				$(this).find("td.bt_re").find("img").hide().each(function(){
					var n = bName.indexOf($(this).attr("alt"));
					if(n != -1) $(this).show();
				});
				
			}).hover(function(){
				$(this).addClass("tr_on");
			}
			, function(){
				$(this).removeClass("tr_on");
			});
			
			this.displayOrder();
		}
		, displayOrder: function(){
			var $layer = this.$getLayer();
			
			$layer.prev("thead").find("th span").attr("class", "");
			$layer.prev("thead").find("th").eq(this.orderIdx).find("span").addClass("th_t");
		}
		, spinStart: function(){
			var $layer = this.$getLayer();
			
			$layer.hide();
			if($layer.parents("article.reserve_list").find("div#tmpSpin").length == 0){
				$layer.parents("article.reserve_list").append("<div id='tmpSpin' style='position:absolute; width:700px; height:100px;' />");
			}
			$layer.parents("article.reserve_list").find("div#tmpSpin").show().spin();
		}
		, spinEnd: function(){
			var $layer = this.$getLayer();
			
			$layer.parents("article.reserve_list").find("div#tmpSpin").hide().spin(false);
			$layer.show();
		}
		, setOrder: function(idx){
			this.orderIdx = idx;
			this.displayOrder();
		}
		, getOrder: function(){
			return this.orderIdx;
		}
		, getCourseKey: function(n){
			if(n === 0 || n) return this.listData[n]["코스코드"];
			else return this.listData[this.idx]["코스코드"];
		}
		, getKey: function(n){
			if(n === 0 || n) return this.listData[n]["예약코드"];
			else return this.listData[this.idx]["예약코드"];
		}
		, getAreaKey: function(n){
			if(n === 0 || n) return this.listData[n]["지역코드"];
			else return this.listData[this.idx]["지역코드"];
		}
		, getGolfKey: function(n){
			if(n === 0 || n) return this.listData[n]["골프장코드"];
			else return this.listData[this.idx]["골프장코드"];
		}
		, setKey: function(key){
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i]["키"] == key) break;
			}
			if(i<this.listData.length) this.idx = i;
		}
		, $getBtnCourses: function(bCurrent){
			var $layer = this._HTMLDom["$layer"];
			if(bCurrent) $layer = $layer.eq(this.typeIdx);
			
			return $layer.find("tr td:nth-child(2)");
		}
		, $getBtnApplys: function(){
			return this.$getLayer().find("img[alt='예약신청']");
		}
		, setIdx: function(idx){
			this.idx = idx;
		}
		, getReserveTime: function(){
			if(this.idx == null) return null;
			else return this.listData[this.idx]["예약시간"];
		}
		, getGolfName: function(){
			if(this.idx == null) return null;
			else return this.listData[this.idx]["골프장명"];
		}
		, getCourseName: function(){
			if(this.idx == null) return null;
			else return this.listData[this.idx]["코스명"];
		}
	}
	
	
	function clsComm()
	{
		
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			
		}
		// 웨이팅 예약 리스트
		, getWaitingReserveList: function(arg){
			var thisClass = this;
			
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "WatingreservDetailList";
			var options = {
				"dateS":arg["날짜"]
				, "region": arg["지역코드"]
				, "golfClubId": arg["골프장코드"]
				, "search": arg["코스조합"]
				, "courseInfoId": arg["코스코드"]
			}
			_gf.ajax({
				"sid": "WR001"
				, "servicename": serviceName
				, "listcount": 10000
				, "currpageno": 1
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": []
				}
				
				var myState = {
					"": "미신청"
					, "W001": "웨이팅 중"
					, "W002": "확정예약가능"
					, "W003": "미신청"
					, "W004": "예약완료"
					, "W005": "미신청"
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					if(!items.length) items = new Array(items);
					
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						var reservDate = _util.nvl(obj["reservDate"])+"";
						
						res["결과값"].push({
							"예약코드": _util.nvl(obj["reserveSeq"])
							, "웨이팅예약코드": _util.nvl(obj["watingReservSeq"])
							, "골프장코드": _util.nvl(obj["golfClubId"])
							, "골프장명": _util.nvl(obj["golfClubNm"])
							, "코스코드": _util.nvl(obj["courseInfoId"])
							, "코스명": _util.nvl(obj["courseInfoNm"])
							, "시간대": _util.nvl(obj["reservTime"])
							, "예약시간": _util.nvl(obj["reservTimeNm"])
							, "홀명": _util.nvl(obj["holeCnt"])
							, "가격": _util.nvl(obj["maxGreenFee"], 0)
							, "원가": _util.nvl(obj["maxGreenFee"], 0)
							, "내상태코드": _util.nvl(obj["resrvStatus"])
							, "내상태": myState[_util.nvl(obj["resrvStatus"])]
							, "신청대기": _util.nvl(obj["waitCnt"], 0)
						});
					}
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
		// 골프장 코스
		, getGolfCourseList: function(arg){
			var thisClass = this;
			
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "reservSearchRegion";
			document.objGlobal.ajax({
				"sid": "RS001"
				, "servicename": serviceName
			}, {
				"region": arg["지역코드"]
			}, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": document.objGlobal.getResultMsg(ret)
					, "결과값": []
				}
				
				var items = ret["msp"]["contents"]["items"];
				
				if(items){
					if(!items.length) items = new Array(items);
					
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						
						res["결과값"].push({
							"코스코드": obj["course__info__id"]
							, "지역코드": obj["region"]
							, "골프장코드": obj["golfclub__id"]
							, "골프장명": obj["golfclub__name"]
							, "코스명": obj["course__info__name"]
						});
					}
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
		// 웨이팅 예약 신청
		, waitingApply: function(arg){
			var thisClass = this;
			
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "WatingApplySave";
			var options = {
				"reserveSeq": arg["예약코드"]
				, "golfClubId": arg["골프장코드"]
				, "courseInfoId": arg["코스코드"]
				, "reservTime": arg["예약시간"]
				, "reservDate": arg["예약일"]
			}
			_gf.ajax({
				"sid": "WR001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
		// 웹이팅 예약 신청 취소
		, waitingApplyCancel: function(arg){
			var thisClass = this;
			
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "WatingApplyCancel";
			var options = {
				"watingReservSeq": arg["예약코드"]
			}
			_gf.ajax({
				"sid": "WR001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
	}
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objBookingControl = null;
		this.objWeekCalendar = null;
		this.objAreaList = null;
		this.objGolfCourseList = null;
		this.objReserveList = null;
		
		this.bFirst = null;
		
		this._permitStart = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			this._preload();
			
			this.objComm = new clsComm();
			this.objBookingControl = new clsBookingControl();
			this.objWeekCalendar = new clsWeekCalendar();
			this.objAreaList = new clsAreaList();
			this.objGolfCourseList = new clsGolfCourseList();
			this.objReserveList = new clsReserveList();
		
			this._bind();
			this._beforeStart();
		}
		, _preload: function(){
			_gf.spinStart();
			
		}
		, _beforeStart: function(){
			var thisClass = this;
			
			this._permitStart = {
				"좌메뉴": false
			}
			
			_util.executeThread(function(){
				return thisClass.objBookingControl.isLoad();
			}, function(){
				thisClass._permitStart["좌메뉴"] = true;
			});
			
			_util.executeThread(function(){
				for(var key in thisClass._permitStart){
					if(!thisClass._permitStart[key]) return false;
				}
				
				return true;
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
			
			
		}
		, _bind: function(){
			var thisClass = this;
			
			// 달력 선택시
			$(this.objBookingControl).on("calendarChange", null, function(){
				thisClass.objBookingControl.goMainPage();
			});
			
			this.objWeekCalendar.$getLayer().on("click", "th:gt(0)", function(){
				var tName = this.tagName.toUpperCase();
				
				switch(tName){
					case "TH":
						var newDate = thisClass.objWeekCalendar.getDate();
						
						// 주력 이전
						if($(this).hasClass("th_prev")){
							newDate.setDate(newDate.getDate()-thisClass.getCalendarPeriod());
							
							//thisClass.objWeekCalendar.setDate(newDate);
							thisClass.objBookingControl.setCalendarDate(newDate);
							//thisClass.objCalendar.setInfo("시작일", newDate);
							//thisClass.reserveSearch();
						// 주력 이후
						}else if($(this).hasClass("th_next")){
							newDate.setDate(newDate.getDate()+thisClass.getCalendarPeriod());
							
							//thisClass.objWeekCalendar.setDate(newDate);
							thisClass.objBookingControl.setCalendarDate(newDate);
							//thisClass.reserveSearch();
						// 주력 날짜 선택
						}else{
							var idx = thisClass.objWeekCalendar.$getLayer().find("th:gt(1)").index($(this));
							
							newDate = new Date();
							newDate.setTime(thisClass.objWeekCalendar.getDate().getTime());
							newDate.setDate(newDate.getDate() + idx);
							
							thisClass.objWeekCalendar.setSelDate(newDate);
							
							// 리스트 페이지 이동
							thisClass.objBookingControl.goWaitingListPage(newDate);
						}

						break;
				}
			});
			
			// 지역선택
			this.objAreaList.$getLayer().on("change", null, function(){
				// 골프장 리스트 요청
				thisClass.getGolfCourseList();
			});
			
			// 검색
			$("div#container section#main_content").on("click", "img[alt='검색']", function(){
				thisClass.getReserveList();
			});
			
			// 웨이팅신청
			this.objReserveList.$getLayer().on("click", "img[alt='웨이팅신청'], img[alt='신청취소'], img[alt='예약확정']", function(){
				var bName = $(this).attr("alt");
				
				var n = thisClass.objReserveList.$getLayer().find("img[alt='" + bName + "']").index($(this));
				thisClass.objReserveList.setIdx(n);
				
				switch(bName){
					case "웨이팅신청":
						var winWaitingReserve = window.open(_ROOT + "/popup/pop_waiting_app.html", "winWaitingReserve", "width=400, height=400, scrollbars=0");
						if(winWaitingReserve) winWaitingReserve.focus();
						break;
					case "신청취소":
						if(!confirm("웨이팅을 취소하시겠습니까?"))return;
						thisClass.objComm.waitingApplyCancel({
							"예약코드": thisClass.objReserveList.getKey()
							, "콜백": function(ret){
								thisClass.finishWaitingApplyCancel(ret)
							}
						});
						break;
					case "예약확정":
						thisClass.popReserveConfirm();
						break;
				}
			});
		}
		, _start: function(){
			this.objBookingControl._start(this);
			this.objBookingControl.setReserveType(1);
			
			var newDate = this.objBookingControl.getCalendarDate();
			
			var d = new Date();
			d.setTime(_util.getParam("q_date"));
			//주력에 전달
			this.objWeekCalendar.setDate(newDate);
			this.objWeekCalendar.setSelDate(d);
			
			this.objAreaList.setList(_gf.getAreaCodeData());
			
			var q_area = _util.getParam("q_area");
			var q_course = _util.getParam("q_course");
			
			if(q_area){
				this.objAreaList.setKey(q_area);
			}else{
				// 검색
				this.getReserveList();
			}
		}
		// 달력선택
		, setCalendarDate: function(){
			var newDate = this.objBookingControl.getCalendarDate();
			
			//주력에 전달
			this.objWeekCalendar.setDate(newDate);
			
			// 검색
			//this.date_reserve();
			this.reserveSearch();
		}
		// 예약 리스트 요청
		, getReserveList: function(){
			var thisClass = this;
			var selDate = this.objWeekCalendar.getSelDate();
			
			this.objReserveList.spinStart();
			
			this.objComm.getWaitingReserveList({
				"지역코드": this.objAreaList.getValue()
				, "골프장코드": this.objGolfCourseList.getGolfKey()
				, "코스코드": this.objGolfCourseList.getCourseKey()
				, "코스조합": this.objBookingControl.getAreaGolfValues()
				, "날짜": selDate.getFullYear() + ("00" + (selDate.getMonth()+1)).substrEx(-2) + ("00" + selDate.getDate()).substrEx(-2)
				, "정렬": this.objReserveList.getOrder()
				, "콜백": function(ret){
					thisClass.finishWaitingReserveList(ret);
				}
			});
		}
		// 골프장 리스트 요청
		, getGolfCourseList: function(){
			var thisClass = this;
			
			this.objGolfCourseList.reset();
			var areaKey = this.objAreaList.getValue();
			
			if(!areaKey) return;
			
			// 골프장 리스트 요청
			this.objComm.getGolfCourseList({
				"지역코드": areaKey
				, "콜백": function(ret){
					thisClass.finishGolfCourseList(ret);
				}
			});
		}
		// 골프장 리스트 완료
		, finishGolfCourseList: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.objGolfCourseList.setList(ret["결과값"]);
			
			if(!this.bFirst){
				var ck = _util.getParam("q_course");
			
				if(ck){
					this.objGolfCourseList.setCourseKey(ck);
				}
				
				this.getReserveList();
				
				this.bFirst = true;
			}
		}
		// 예약리스트 완료
		, finishWaitingReserveList: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.objReserveList.spinEnd();
			this.objReserveList.setList(ret["결과값"]);
		}
		// 웨이팅 신청 완료
		, finishWaitingApply: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			document.location.reload();
		}
		// 웨이팅 신청취소 완료
		, finishWaitingApplyCancel: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			document.location.reload();
		}
		// 웨이팅 신청 팝업에서 요청하는 웨이팅 정보
		, getWaitingReserveInfo: function(){
			var reserveKey = this.objReserveList.getKey();
			var golfKey = this.objReserveList.getGolfKey();
			var golfName = this.objReserveList.getGolfName();
			var courseKey = this.objReserveList.getCourseKey();
			var courseName = this.objReserveList.getCourseName();
			var selDate = this.objWeekCalendar.getSelDate();
			var weekDay = ["일", "월", "화", "수", "목", "금", "토"];
			var szTime = this.objReserveList.getReserveTime();
			
			var szNote = selDate.getFullYear() + "년 " + ("00" + (selDate.getMonth()+1)).substrEx(-2) + "월 " + ("00" + selDate.getDate()).substrEx(-2) + "일(" + weekDay[selDate.getDay()] + ")<br>" + golfName + " " + courseName + " " + szTime + "<br>";
			var reserveInfo = {
				"예약코드": reserveKey
				, "골프장코드": golfKey
				, "코스코드": courseKey
				, "예약시간": szTime
				, "예약일": selDate.getFullYear() + ("00" + (selDate.getMonth()+1)).substrEx(-2) + ("00" + selDate.getDate()).substrEx(-2)
			}
			
			var ret = {
				"예약코드": reserveKey
				, "내용": szNote
				, "예약정보": reserveInfo
			}
			
			return ret;
		}
		// 웨이팅 신청하기
		, closeWaitingApply: function(w, reserveInfo){
			var thisClass = this;
			if(w) w.close();
			
			reserveInfo["콜백"] = function(ret){
				thisClass.finishWaitingApply(ret);
			}
			
			this.objComm.waitingApply(reserveInfo);
		}
		// 예약 상세 이동
		, goReserveInfoPage: function(n){
			var opt = {
				"q_reserve":  this.objReserveList.getKey(n)
				, "q_area": this.objReserveList.getAreaKey(n)
				, "q_golf": this.objReserveList.getGolfKey(n)
				, "q_course": this.objReserveList.getCourseKey(n)
				, "q_areagolf": _util.getParam("q_areagolf")
				, "q_sdate": _util.getParam("q_sdate")
				, "q_date": _util.getParam("q_date")
			}
			var szLink = _ROOT + "/booking/reserve_view.html" + _util.object2paramString(opt);
			document.location.href = szLink;
		}
		// 예약확정 팝업
		, popReserveConfirm: function(q_seq){
			var szLink = _ROOT + "/popup/pop_waiting_app_ok.html?q_seq" + q_seq;
			var winWaitingConfirm = window.open(szLink, "winWaitingConfirm", "width:600, height=300, scrollbars=0");
			if(winWaitingConfirm) winWaitingConfirm.focus();
		}
	}
	
	$.ajax({
		url: _ROOT + "/booking/js/booking_common.js"
		, type: "get"
		, dataType: "script"
		, async: false
		, success: function(ret){
			document.objControl = new clsControl();
			document.objControl._init();
		}
		, error: function(){
			alert("error");
		}
	});
});
